﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityModel;
using System.Data.Entity;
using System.Web;
using System.Data.Objects;


namespace Services
{

    public class DbContextHelper : DbContext
    {
        public static ShopDbEntities GetCurrentDbContext()
        {
            if (!HttpContext.Current.Items.Contains("CurrentDbContext"))
                HttpContext.Current.Items.Add("CurrentDbContext", new ShopDbEntities());
            return (ShopDbEntities)HttpContext.Current.Items["CurrentDbContext"];
        }

        public static void DisposeCurrentDbContext()
        {
            if (HttpContext.Current.Items.Contains("CurrentDbContext"))
            {
                ShopDbEntities bdc = (ShopDbEntities)HttpContext.Current.Items["CurrentDbContext"];
                bdc.Dispose();
                HttpContext.Current.Items.Remove("CurrentDbContext");
            }
        }
    }
}
